package com.itheima.controller;

import com.itheima.pojo.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
public class FileUpLoadController {
    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws IOException {
        //把文件的内容传递到本地磁盘上
        String orginalFilename = file.getOriginalFilename();

        String filename = UUID.randomUUID().toString()+orginalFilename.substring(orginalFilename.lastIndexOf("."));
        file.transferTo(new File("C:\\Users\\熊\\Desktop\\files\\"+filename));
        return Result.success("C:\\Users\\熊\\Desktop\\files\\"+filename);
    }
}
